import request from '../utils/request'

// ==================== 工单提交相关 ====================

/**
 * 提交维修工单
 */
export function submitRepairOrder(data) {
  return request({
    url: '/h5/repair/submit',
    method: 'post',
    data: data
  })
}

/**
 * 上传故障图片
 */
export function uploadFaultImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/h5/upload/image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// ==================== 工单查询相关 ====================

/**
 * 根据工单号查询工单详情
 */
export function getRepairOrderByCase(caseNo) {
  return request({
    url: `/h5/repair/track/${caseNo}`,
    method: 'get'
  })
}

/**
 * 查询我的工单列表
 */
export function getMyRepairOrders(params) {
  return request({
    url: '/h5/repair/my-orders',
    method: 'get',
    params: params
  })
}

/**
 * 根据ID查询工单详情
 */
export function getRepairOrderDetail(id) {
  return request({
    url: `/h5/repair/${id}`,
    method: 'get'
  })
}

// ==================== 报价相关 ====================

/**
 * 确认报价
 */
export function confirmQuote(id, data) {
  return request({
    url: `/h5/repair/quote/${id}/confirm`,
    method: 'post',
    data: data
  })
}

/**
 * 拒绝报价
 */
export function rejectQuote(id, data) {
  return request({
    url: `/h5/repair/quote/${id}/reject`,
    method: 'post',
    data: data
  })
}

// ==================== 工单操作相关 ====================

/**
 * 取消工单
 */
export function cancelRepairOrder(id, data) {
  return request({
    url: `/h5/repair/${id}/cancel`,
    method: 'post',
    data: data
  })
}

/**
 * 催单
 */
export function urgeRepairOrder(id) {
  return request({
    url: `/h5/repair/${id}/urge`,
    method: 'post'
  })
}

/**
 * 提交反馈
 */
export function submitFeedback(id, data) {
  return request({
    url: `/h5/repair/${id}/feedback`,
    method: 'post',
    data: data
  })
}

/**
 * 确认收货
 */
export function confirmReceipt(id) {
  return request({
    url: `/h5/repair/${id}/confirm-receipt`,
    method: 'post'
  })
}

// ==================== 服务中心相关 ====================

/**
 * 查询服务中心列表
 */
export function getServiceCenters(params) {
  return request({
    url: '/h5/service-centers',
    method: 'get',
    params: params
  })
}

/**
 * 查询服务中心详情
 */
export function getServiceCenterDetail(id) {
  return request({
    url: `/h5/service-centers/${id}`,
    method: 'get'
  })
}

/**
 * 查询可预约时间段
 */
export function getAvailableTimeSlots(centerId, date) {
  return request({
    url: `/h5/service-centers/${centerId}/time-slots`,
    method: 'get',
    params: { date }
  })
}

// ==================== 设备相关 ====================

/**
 * 查询设备型号列表
 */
export function getDeviceModels() {
  return request({
    url: '/h5/device-models',
    method: 'get'
  })
}

/**
 * 根据SN码查询设备信息
 */
export function getDeviceBySN(sn) {
  return request({
    url: `/h5/devices/sn/${sn}`,
    method: 'get'
  })
}

/**
 * 检查保修状态
 */
export function checkWarranty(sn) {
  return request({
    url: `/h5/devices/warranty/${sn}`,
    method: 'get'
  })
}

// ==================== 地址相关 ====================

/**
 * 查询我的地址列表
 */
export function getMyAddresses() {
  return request({
    url: '/h5/addresses',
    method: 'get'
  })
}

/**
 * 添加地址
 */
export function addAddress(data) {
  return request({
    url: '/h5/addresses',
    method: 'post',
    data: data
  })
}

/**
 * 更新地址
 */
export function updateAddress(id, data) {
  return request({
    url: `/h5/addresses/${id}`,
    method: 'put',
    data: data
  })
}

/**
 * 删除地址
 */
export function deleteAddress(id) {
  return request({
    url: `/h5/addresses/${id}`,
    method: 'delete'
  })
}

